package com.yocard.yxyd.ui.presenter;

import com.yocard.yxyd.base.CommonSubscriber;
import com.yocard.yxyd.base.RxPresenter;
import com.yocard.yxyd.http.HttpManager;
import com.yocard.yxyd.ui.contract.AddflowContract;
import com.yocard.yxyd.utils.RxUtil;

import org.json.JSONArray;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

/**
 * Created on 2019/4/17.
 */
public class AddflowPresenter extends RxPresenter<AddflowContract.View> implements AddflowContract.Presenter {

    @Inject
    public AddflowPresenter(HttpManager manager) {
        super(manager);
    }

    @Override
    public void fetchStatus() {
        addSubscribe(httpManager.getTrackStatus().compose(RxUtil.rxSchedulerHelper())
                    .subscribeWith(new CommonSubscriber<Map<String, String>>(mView) {
                        @Override
                        public void onSuccess(Map<String, String> data) {
                            try {
                                mView.onFetStatusSuccess(data);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }));
    }

    @Override
    public void commitTrack(String id,String type, String remark) {
        addSubscribe(httpManager.commitTrack(id,type,remark)
                    .compose(RxUtil.rxSchedulerHelper())
                    .subscribeWith(new CommonSubscriber<List<Object>>(mView) {
                        @Override
                        public void onSuccess(List<Object> data) {
                            mView.onCommitSuccess();
                        }
                    }));
    }
}
